<?php

require_once 'Basic.php';

class FormFieldCEP extends FormFieldType {
  
  public function __construct() {
    $this->htmlClass = "cepField";
    $this->inputSize = 15;
    $this->htmlId = null;
  }
  
  public function clearHtmlClass() {
    $this->htmlClass = "cepField";
  }

  public function getHtml($name, $value) {
    return $this->commonHtml($name, $value);
  }

  public function validate($input) {
    return FormFieldCEP::validateCEP($input);
  }

  public static function validateCEP($cep) {
    if(preg_match("%^[0-9]{5}[0-9]{3}$%", $cep) === 1) {
      return true;	// está tudo certo
    }
    else {
      return "O CEP deve estar no formado XXXXX-XXX. Foi passado \"<span class='userInput'>${cep}</span>\".";
    }
  }
  
}
